

package com.hazelcast.client.impl.protocol.task.replicatedmap;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.codec.ReplicatedMapEndEntryViewIterationCodec;
import com.hazelcast.client.impl.protocol.task.AbstractPartitionMessageTask;
import com.hazelcast.instance.impl.Node;
import com.hazelcast.internal.nio.Connection;
import com.hazelcast.replicatedmap.impl.ReplicatedMapService;
import com.hazelcast.replicatedmap.impl.operation.EndEntryViewIterationOperation;
import com.hazelcast.security.SecurityInterceptorConstants;
import com.hazelcast.security.permission.ActionConstants;
import com.hazelcast.security.permission.ReplicatedMapPermission;
import com.hazelcast.spi.impl.operationservice.Operation;

import java.security.Permission;

public class ReplicatedMapEndEntryViewIterationMessageTask extends AbstractPartitionMessageTask<ReplicatedMapEndEntryViewIterationCodec.RequestParameters> {
    public ReplicatedMapEndEntryViewIterationMessageTask(ClientMessage clientMessage, Node node, Connection connection) {
        super(clientMessage, node, connection);
    }

    @Override
    protected Operation prepareOperation() {
        return new EndEntryViewIterationOperation(parameters.name, parameters.cursorId);
    }

    @Override
    protected String getUserCodeNamespace() {
        return null;
    }

    @Override
    public Permission getRequiredPermission() {
        return new ReplicatedMapPermission(parameters.name, ActionConstants.ACTION_READ);
    }

    @Override
    protected ReplicatedMapEndEntryViewIterationCodec.RequestParameters decodeClientMessage(ClientMessage clientMessage) {
        return ReplicatedMapEndEntryViewIterationCodec.decodeRequest(clientMessage);
    }

    @Override
    protected ClientMessage encodeResponse(Object response) {
        return ReplicatedMapEndEntryViewIterationCodec.encodeResponse();
    }

    @Override
    public String getServiceName() {
        return ReplicatedMapService.SERVICE_NAME;
    }

    @Override
    public String getDistributedObjectName() {
        return parameters.name;
    }

    @Override
    public String getMethodName() {
        return SecurityInterceptorConstants.END_ENTRYVIEW_ITERATION;
    }

    @Override
    public Object[] getParameters() {
        return new Object[]{parameters.cursorId};
    }
}
